package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.AdminOrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import com.sky.vo.OrdersPageVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 订单
 *
 * @author iTaotao
 * @version 1.0
 * @date 2023/08/04 16:27:03
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/order")
public class AdminOrderController {
    private final AdminOrderService adminOrderService;

    /**
     * 取消订单
     *
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping("/cancel")
    public Result<?> cancelOrder(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        adminOrderService.cancelOrder(ordersCancelDTO);
        return Result.success();
    }

    /**
     * 订单分页
     *
     * @param ordersPageQueryDTO 订单查询页面dto
     * @return {@link Result}<{@link OrdersPageVO}>
     */
    @GetMapping("/conditionSearch")
    public Result<PageResult> selectPage(OrdersPageQueryDTO ordersPageQueryDTO) {
        PageResult page = adminOrderService.selectPage(ordersPageQueryDTO);
        return Result.success(page);

    }

    /**
     * 订单数量统计
     *
     * @return {@link Result}<{@link OrderStatisticsVO}>
     */
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> OrdersStatis() {
        OrderStatisticsVO orderStatisticsVO = adminOrderService.OrdersStatis();
        return Result.success(orderStatisticsVO);
    }

    /**
     * 确认订单
     *
     * @param ordersConfirmDTO 订单确认dto
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping("/confirm")
    public Result<?> confirmOrder(@RequestBody OrdersConfirmDTO ordersConfirmDTO) {
        adminOrderService.confirmOrder(ordersConfirmDTO);
        return Result.success();
    }

    /**
     * 拒绝订单
     *
     * @param ordersRejectionDTO 订单被拒绝dto
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping("/rejection")
    public Result<?> rejectionOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        adminOrderService.rejectionOrder(ordersRejectionDTO);
        return Result.success();

    }

    /**
     * 派送订单
     *
     * @param id id
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping("/delivery/{id}")
    public Result<?> DeliveryOrder(@PathVariable Long id) {
        adminOrderService.DeliveryOrder(id);
        return Result.success();
    }

    /**
     * 完整订单
     *
     * @param id id
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping("/complete/{id}")
    public Result<?>completeOrder(@PathVariable Long id){
        adminOrderService.completeOrder(id);
        return Result.success();
    }

    /**
     * 选择订单细节id
     *
     * @param id id
     * @return {@link Result}<{@link OrderVO}>
     */
    @GetMapping("/details/{id}")
    public Result<OrderVO> selectOrderDetailById(@PathVariable Long id){
        OrderVO orderVO = adminOrderService.selectOrderDetailById(id);
        return Result.success(orderVO);
    }
}
